//
//  OrderDetailGoodsTableViewCell.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/8/3.
//  Copyright © 2018年 四川中农. All rights reserved.
//

import UIKit

class OrderDetailGoodsTableViewCell: UITableViewCell {
    
    @IBOutlet weak var goodsImage: UIImageView!
    @IBOutlet weak var goodsName: UILabel!
    @IBOutlet weak var bazaarPrice: UILabel!
    @IBOutlet weak var price: UILabel!
    @IBOutlet weak var totalPrice: UILabel!
    @IBOutlet weak var goodsCount: UILabel!
    @IBOutlet weak var viewLine: UIView!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func reload(withModel model:SiteGoodsModel){
        self.goodsName.text = model.name
        self.goodsImage.my_setImage(url: model.img, placeholder: Api.placeHolder.rawValue)
        self.bazaarPrice.attributedText = Utils.labelTextDeleLine(normalString: "市场价：¥\(model.marketPrice)", deleString: "\(model.marketPrice)")
        
        let str = "￥" + "\(model.price)" + "/" + model.spec + "  " + model.specDesc
        let attribute = NSMutableAttributedString.init(string: str)
        attribute.addAttributes([NSAttributedStringKey.font:UIFont.systemFont(ofSize: 11)], range: NSString.init(string: str).range(of: model.specDesc))
        self.price.attributedText = attribute
        
        let currentPrice = model.price
        let count = model.num
        var attributeString = NSMutableAttributedString.init(string: "小计：¥" + "\(currentPrice * Double(count))")
        attributeString.addAttributes([NSAttributedStringKey.font:UIFont.systemFont(ofSize: 16)], range: NSString.init(string: "小计：¥" + "\(currentPrice * Double(count))").range(of: "\(currentPrice * Double(count))".getPriceInteger()))
        attributeString = NSMutableAttributedString.init(attributedString: attributeString)
        attributeString.addAttributes([NSAttributedStringKey.foregroundColor:UIColor.init(hexColor: "#ed4848")], range: NSString.init(string: "小计：¥" + "\(currentPrice * Double(count))").range(of: "¥" + "\(currentPrice * Double(count))"))
        self.totalPrice.attributedText = attributeString
        
        self.goodsCount.text = (model.specDesc == "" ? "" : "model.specDesc" + "×") + "\(count)" + model.spec
    }

}
